package com.herench.bunch.clinic.handler;

import com.alibaba.fastjson.JSON;
import com.herench.bunch.clinic.agent.ClinicAgent;
import com.herench.bunch.clinic.convert.AppointConvert;
import com.herench.bunch.clinic.convert.QueryAppointMsgConvert;
import com.herench.bunch.clinic.support.AbstractClinicMessageHandler;
import com.herench.bunch.clinic.support.ProxyMsgTemplate;
import com.herench.bunch.commons.annotation.Handler;
import org.dom4j.Document;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Handler(code = "202280", name = "查询患者预约信息" ,messageConvertClass = QueryAppointMsgConvert.class)
public class QueryAppointMsgHandlerClinic extends AbstractClinicMessageHandler {

    @Autowired
    private ClinicAgent clinicAgent;

    @Override
    protected Object proxyInvoke(Object inMessage) throws Exception {
        Document message = (Document) inMessage;
        Document doc = ProxyMsgTemplate.getOutMsgTpl(message.asXML());
        Map<String,Object> params = new HashMap<>();
        params.put("HISPatientID",doc.getRootElement().elementTextTrim("HISPatientID"));
        List<Map<String,Object>> res = clinicAgent.QueryAppointMsg(params);
        String req = JSON.toJSONString(res);
        return req;
    }
}
